package com.mstore.dao;

import java.util.List;

import com.mstore.pojo.BaseAct;

public class BaseActDao extends SuperDao {

	public void save(BaseAct baseact) {
		super.save(baseact);
	}

	public void delete(BaseAct baseact) {
		super.delete(baseact);
	}

	public void updateBaseAct(BaseAct baseact) {
		/*
		 * String sql =
		 * "update ubcenter.c_base_account set balance = "+baseact.getBalance
		 * ()+",score="
		 * +baseact.getScore()+",level='"+baseact.getLevel()+"' where id="
		 * +baseact.getId(); super.executeUpdate(sql);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("update ubcenter.c_base_account set balance = ");
		sb.append(baseact.getBalance());
		sb.append(",score=");
		sb.append(baseact.getScore());
		sb.append(",level='");
		sb.append(baseact.getLevel());
		sb.append("' where id=");
		sb.append(baseact.getId());
		super.executeUpdate(sb.toString());
	}

	public Object getOneBaseact(BaseAct baseact) {
		String sql = "from BaseAct where memberId=?";
		List<Object> objects = super.getObject(sql,
				new Object[] { baseact.getMemberId() });
		if (objects.size() != 0) {
			return objects.get(0);
		} else {
			return null;
		}
	}

	public void delBaseActByMemId(BaseAct baseact) {
		/*String sql = "delete from ubcenter.c_base_account where member_id = "
				+ baseact.getMemberId();
		super.executeUpdate(sql);*/
		
		StringBuilder sb=new StringBuilder();
		sb.append("delete from ubcenter.c_base_account where member_id = ");
		sb.append(baseact.getMemberId());
		super.executeUpdate(sb.toString());
	}

	public void updateBaseActByScore(BaseAct baseact) {
		/*String sql = "update ubcenter.c_base_account set score="
				+ baseact.getScore() + ",level='" + baseact.getLevel()
				+ "' where id=" + baseact.getId();
		super.executeUpdate(sql);*/
		
		StringBuilder sb=new StringBuilder();
		sb.append("update ubcenter.c_base_account set score=");
		sb.append(baseact.getScore());
		sb.append(",level='");
		sb.append(baseact.getLevel());
		sb.append("' where id=");
		sb.append(baseact.getId());
		super.executeUpdate(sb.toString());
	}

	public void updateBaseActByBalance(BaseAct baseact) {
		/*String sql = "update ubcenter.c_base_account set balance = "
				+ baseact.getBalance() + " where id=" + baseact.getId();
		super.executeUpdate(sql);*/
		
		StringBuilder sb=new StringBuilder();
		sb.append("update ubcenter.c_base_account set balance = ");
		sb.append(baseact.getBalance());
		sb.append("' where id=");
		sb.append(baseact.getId());
		super.executeUpdate(sb.toString());
		
	}

	/**
	 * 修改会员金额
	 */
	public void updateBaseActByBalanceByMemberId(BaseAct baseact) {
		/*String sql = "update ubcenter.c_base_account set balance = "
				+ baseact.getBalance() + " where member_id="
				+ baseact.getMemberId();
		super.executeUpdate(sql);*/
		
		StringBuilder sb=new StringBuilder();
		sb.append("update ubcenter.c_base_account set balance = ");
		sb.append(baseact.getBalance());
		sb.append("' where member_id=");
		sb.append(baseact.getMemberId());
		super.executeUpdate(sb.toString());
	}
	
	/**
	 * 查询全部
	 */
	public List<Object> getAllBaseActs() {
		String sql = "from BaseAct";
		return super.find(sql);
	}

}
